#include "NetworkMessage.h"
#include "TestBase.h"

TestBase::TestBase()
{
	info.Name = "NetworkMessage Test 1";
	info.Category = 0x2101;
	info.CategoryName = "NetworkMessage";
	info.File = __FILE__;
}

bool TestBase::Run()
{
	unsigned char buf[16] = {
		0x01, 0x02, 0x04, 0x08,
		0x10, 0x20, 0x40, 0x80,
		0x03, 0x06, 0x0c, 0x18,
		0x30, 0x60, 0xc0, 0xff
	}, bufO[16];
	int fail = 0, i = 0;
	NetworkMessage msg1, msg2;
	msg1.WriteRaw(buf, 16);
	msg2 = msg1;
	if (msg2.ReadRaw(bufO, 16) != 16)
	{
		std::cout << GetTestInfo()->Name << " failure info" << std::endl;
		std::cout << "Could not read from msg2" << std::endl;
		return false;
	}
	for (i = 0; i < 16; i++)
	{
		if (buf[i] != bufO[i])
		{
			fail = 1;
			break;
		}
	}
	if (fail != 0)
	{
		std::cout << GetTestInfo()->Name << " failure info" << std::endl;
		printf("Output          : %.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x\n", (int)buf[0], (int)buf[1], (int)buf[2], (int)buf[3], (int)buf[4], (int)buf[5], (int)buf[6], (int)buf[7]);
		printf("                : %.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x\n", (int)buf[8], (int)buf[9], (int)buf[10], (int)buf[11], (int)buf[12], (int)buf[13], (int)buf[14], (int)buf[15]);
		printf("Expected output : %.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x\n", (int)bufO[0], (int)bufO[1], (int)bufO[2], (int)bufO[3], (int)bufO[4], (int)bufO[5], (int)bufO[6], (int)bufO[7]); 
		printf("                : %.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x\n", (int)bufO[8], (int)bufO[9], (int)bufO[10], (int)bufO[11], (int)bufO[12], (int)bufO[13], (int)bufO[14], (int)bufO[15]);
		printf("Same?           : %s\n", (fail == 0) ? "true" : "false");
		return false;
	}
	return true;
}